﻿<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>CMS - 后台管理系统</title>
    <link href="/resource/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="/resource/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
    <link href="/resource/css/ionicons.min.css" rel="stylesheet" type="text/css" />
    <link href="/resource/css/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div class="row">
    <div class="col-md-12">
    	<h1 class="panel-heading">系统设置</h1>
        <!--breadcrumbs start -->
        <ul class="breadcrumb">
				<li><a href="/admin/dashboard/toIndex"><i class="fa fa-home"></i> 首页</a></li>
				<li class="active">系统设置</li>
			</ul>
        <!--breadcrumbs end -->
    </div>
</div>
<section class="panel">
    <div class="panel-body">
        <form class="col s12" id="form1" th:object="${user}">
        	<input name="id" type="hidden" th:value="*{id}">
        	<div class="form-group form-control-small">
				<div for="username"><b>当前用户：</b><span th:text="*{username}"></span></div>
            </div>
            <div class="form-group form-control-small">
				<label for="oldPwd">原密码：</label>
                <input id="oldPwd" name="oldPwd" type="password" class="form-control">
            </div>
            <div class="form-group form-control-small">
				<label for="newPwd">新密码：</label>
				<input id="newPwd" name="newPwd" type="password" class="form-control">
            </div>
            <div class="form-group form-control-small">
				<label for="reNewPwd">重复新密码：</label>
				<input id="reNewPwd" name="reNewPwd" type="password" class="form-control">
            </div>
            <div class="form-btn-group-left">
            	<button type="button" class="btn btn-info" id="save">修改密码</button>
            </div>
        </form>
    </div>
</section>
<!-- jQuery 2.0.2 -->
<script src="/resource/js/jquery.min.js"></script>
<script src="/resource/js/jquery.serializejson.js"></script>
<script src="/resource/js/coco-message/coco-message.js"></script>
<script>
	(function(){
		$("#save").click(function(){
			var oldPwd = $("#oldPwd").val();
			var newPwd = $("#newPwd").val();
			var reNewPwd = $("#reNewPwd").val();
			
			if(oldPwd == null || oldPwd == ""){
				cocoMessage.error("原密码不能为空");
				return;
			}
			
			if(newPwd == null || newPwd == ""){
				cocoMessage.error("新密码不能为空");
				return;
			}
			
			if(reNewPwd == null || reNewPwd == ""){
				cocoMessage.error("重复新密码不能为空");
				return;
			}
			
			if(reNewPwd != newPwd){
				cocoMessage.error("两次密码输入不一致");
				return;
			}
			
			var obj = $('#form1').serializeJSON();
			$.ajax({
				url: "/admin/user/updatePwd",
				type: "POST",
				data: JSON.stringify(obj),
			    dataType: "json",
			    contentType:"application/json;charset=utf-8",
				success: function(data) {
					if(data.success){
						cocoMessage.success(data.info);
					}else{
						cocoMessage.error(data.info);
					}
				}
			});
		});
	})()
</script>			
</body>
</html>
